//
//  MLAChangePasswordVC.m
//  MagicLampApp
//
//  Created by Zheng on 2018/12/19.
//  Copyright © 2018 zheng.magic.lamp.app. All rights reserved.
//

#import "MLAChangePasswordVC.h"
#import "MLABaseFieldView.h"

@interface MLAChangePasswordVC () {
    MLABaseFieldView *oldPwdView;
    MLABaseFieldView *newPwdView;
}

@end

@implementation MLAChangePasswordVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self configTitle:@"更改密码"];
    
    oldPwdView = [[MLABaseFieldView alloc] init];
    NSDictionary *oldInfoDic = CX_GetFieldInfoDic(@"旧密码", @"请输入", @"30", @"1", @"1", @"0", @"");
    MLABaseFieldModel *oldModel = [MLABaseFieldModel mj_objectWithKeyValues:oldInfoDic];
    oldPwdView.model = oldModel;
    [self.view addSubview:oldPwdView];
    [oldPwdView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleView.mas_bottom).offset(20);
        make.left.right.equalTo(self.view);
        make.height.mas_equalTo(85);
    }];
    
    newPwdView = [[MLABaseFieldView alloc] init];
    NSDictionary *newInfoDic = CX_GetFieldInfoDic(@"新密码", @"请输入", @"30", @"1", @"1", @"0", @"");
    MLABaseFieldModel *newModel = [MLABaseFieldModel mj_objectWithKeyValues:newInfoDic];
    newPwdView.model = newModel;
    [self.view addSubview:newPwdView];
    [newPwdView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.height.mas_equalTo(self->oldPwdView);
        make.top.equalTo(self->oldPwdView.mas_bottom);
    }];
    
    UIButton *commitBtn = [self getCommitButtonWithTitle:@"确认"];
    [commitBtn addTarget:self action:@selector(commitBtnAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:commitBtn];
    [commitBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.right.mas_equalTo(-15);
        make.height.mas_equalTo(40);
        make.bottom.mas_equalTo(-34);
    }];

}

- (void)commitBtnAction {
    CX_Log(@"确认修改密码");
    if (oldPwdView.inputText.length == 0) {
        [MLAHudManage showMessage:@"请输入密码"];
        return;
    }
    
    if (newPwdView.inputText.length == 0) {
        [MLAHudManage showMessage:@"请输入新密码"];
        return;
    }
    
    NSDictionary *params = @{@"raw_password":oldPwdView.inputText,
                             @"new_password":newPwdView.inputText,
                             @"new_passwords":newPwdView.inputText};
    
    [MLAHttpManage postHostType:MLAHttpHostType_Api api:kSavePassowrd params:params success:^(id  _Nonnull response, NSString * _Nonnull msg) {
        [self.navigationController popViewControllerAnimated:YES];
    } failure:^{
        
    }];
    
}


@end
